﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Linq;
using Hammock.Web;

namespace Payton.WP7.Common.Model
{
    public class SNSRequest
    {
        public SNSRequest()
        {
            Parameters = new List<SNSParameter>();
            WebMethod = Hammock.Web.WebMethod.Get;
        }

        WebMethod webMethod;

        public WebMethod WebMethod
        {
            get { return webMethod; }
            set { webMethod = value; }
        }

        List<SNSParameter> parameters;

        public List<SNSParameter> Parameters
        {
            get { return parameters; }
            set { parameters = value; }
        }

        Func<SNSParameter, bool> predicate;

        public Func<SNSParameter, bool> Predicate
        {
            get { return predicate; }
            set { predicate = value; }
        }

        SNSType type;

        public SNSType Type
        {
            get { return type; }
            set { type = value; }
        }

        string method;

        public string Method
        {
            get { return method; }
            set { method = value; }
        }

        public SNSRequest(IEnumerable<SNSParameter> parameters)
            : this()
        {
            foreach (var item in parameters)
            {
                Parameters.Add(new SNSParameter(item.Name, item.Value));
            }
        }
    }

    public enum ParameterStyle
    {
        Normal, Restful, InHeader,
        Post,
        File,
        FilePath,
        Bytes
    }

    public class SNSParameter
    {
        public SNSParameter(string name, string value)
        {
            Name = name;
            Value = value;
        }
        string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        string value;

        public string Value
        {
            get { return this.value; }
            set { this.value = value; }
        }

        ParameterStyle style = ParameterStyle.Normal;

        public ParameterStyle Style
        {
            get { return style; }
            set { style = value; }
        }

    }

    public class SNSFileParameter:SNSParameter
    {
        public SNSFileParameter(string name, string path, byte[] value)
            : base(name, path)
        {
            Name = name;
            Value = path;
            Style = ParameterStyle.Bytes;
            Bytes = value;
        }

        public byte[] Bytes { get; set; }
    }

    /// <summary>
    /// Comparer class used to perform the sorting of the query parameters
    /// </summary>
    public class ParameterComparer : IComparer<SNSParameter>
    {
        public int Compare(SNSParameter x, SNSParameter y)
        {
            if (x.Name == y.Name)
            {
                return string.Compare(x.Value, y.Value);
            }
            else
            {
                return string.Compare(x.Name, y.Name);
            }
        }
    }
}
